<template>
  <div class="home">
    <div class="banner">
      <el-carousel height="450px">
        <el-carousel-item v-for="(val, key) in data" :key="key">
          <img :src="val.picUrl" class="elImg">
        </el-carousel-item>
      </el-carousel>
    </div>

    <div v-for="(item, i) in allList" :key="i">

      <div class="ad" v-if="item.type == 1">
        <ul>
          <li v-for="(ad, i) in item.panelContents" :key="i">
            <img :src="ad.picUrl">
          </li>
        </ul>
      </div>

      <div class="hotdetail" v-if="item.type == 2">
        <div class="hotdetail_menu">{{item.name}}</div>
        <div class="hotdetail_main">
          <ul>
            <li v-for="(v, k) in item.panelContents" :key="k">
              <img :src="v.picUrl">
              {{v.productName}}
              <p>{{v.salePrice | getMoney}}</p>
            </li>
          </ul>
        </div>
      </div>

    </div>
    
    <div class="selectDetail"></div>
  </div>
</template>

<script>
  export default {
    name: "Home",
    data () {
      return {
        bannerImg: [
          {img: require("assets/images/banner/01.jpg"), title: "坚果pro3", price: 100},
          {img: require("assets/images/banner/02.jpg"), title: "坚果pro2", price: 20},
        ],
        data: [],
        allList: []
      }
    },
    created() {
      this.getData();
    },
    methods: {
      getData() {
        this.$http.get("http://api.mm2018.com:8090/api/goods/home")
          .then(res => {
            this.allList = res.data.result;
            this.data = res.data.result[0].panelContents;
          })
      }
    },
    filters: {
      getMoney(price) {
        return price + "￥";
      }
    }
  }

</script>

<style scoped>
  .banner{
    width: 960px;
    height: 415px;
    margin: 0 auto;
    margin-top: 30px;
    border-radius: 10px;
    overflow: hidden;
  }
  .elImg{
    width: 100%;
    height: 100%;
  }
  ul{
    margin: 0;
    padding: 0;
    list-style-type: none;
  }
  .ad{
    width: 960px;
    height: 150px;
    margin: 20px auto;
    background-color: #000;
    border-radius: 10px;
    border: 1px solid #ccc;
    overflow: hidden;
  }
  .ad ul{
    width: 100%;
    display: flex;
  }
  .ad ul li{
    flex: 1;
  }
  .ad ul li img{
    width: 100%;
  }
  .hotdetail{
    width: 960px;
    height: 350px;
    margin: 0 auto;
    background: #FFF;
    border-radius: 10px;
    border: 1px solid #ccc;
    overflow: hidden;
  }
  .hotdetail_menu{
    height: 51px;
    line-height: 51px;
    text-indent: 30px;
    border-bottom: 1px solid #ccc;
  }
  .hotdetail_main{
    width: 100%;
    height: 100px;
  }
  .hotdetail_main ul{
    display: flex;
  }
  .hotdetail_main ul li{
    flex: 1;
    text-align: center;
  }
  .hotdetail_main ul li p{
    margin-top: 10px;
    color: red;
  }
  .hotdetail_main ul li img{
    display: flex;
    width: 170px;
    margin: 30px auto;
  }
</style>